# 变量 int,float,string,bool
number = 1
floatNumber = 99.9
str = "hello coucou!"
boo = True

a = b = c = 1
print(a, b, c)
a, b, c = 1, 2, 3
print(number, floatNumber, str)

# string：字符串：装一串字符
str2 = "hello world"; 
print(str2)      # 输出：hello world    
print(str2[5])   # 根据下标定位元素 输出：空格
print(str2[2:8]) # 截取字符串：[2,8) 输出：llo wo
print(str2[4:])  # 截取字符串：[4,len) 输出：o world                      
print(str2 * 5)  # 重复输出内容五次
print("hello" + " " + "world") # 字符串拼接

# list: 列表:什么类型都能装
list2 = [1,1,1,1,1]
list1 = [False, 99999.00001, "djlasjdlaskd", 100, list2]
print(list1)      # 与字符串操作高度相似
list1[0] = True ; print(list1)

# tuple: 元组(与list的唯一差距：仅可读)
tuple1 = (88, 77.8, True, list2, "abcdefg")
# tuple1[0] = 0 无法修改值

# dictionary: 字典(key-value)
dic = {0 : "这里是0", "陈" : "coucou", 99.9 : False}
print(dic["陈"])    # 检索
print(dic.keys())   # 获取所有的键key
print(dic.values()) # 获取所有的值value

# 算术运算符：+，-，*，/，%，**，//
divide = 7 / 5; print(divide)    # 除以，正常得到小数
divide2 = 7 // 5; print(divide2) # 除以，向下取整
print(pow(2, 10));  print(2**10) # 2的10次幂
remainder = 7 % (5 * 2);  print(remainder) # 取余

# 比较运算符：>,<,==,!=,>=,<=
flag = 1 <= 2; print(flag)  # 赋值运算符优先级很低

# 赋值运算符：=,+=,-=,*=,/=,%=,**=,//=
num = 2
num = num * 2; num *= 2; print(num) # 等效

# 位运算符：&,|,~,^,<<,>>
num1 = 12 # 二进制：8 + 4: 00001100(1 * 2^3 + 1 * 2^2 + 0 * 2^1 + 0 * 2^0)
num2 = 71 # 二进制：64 + 4 + 2 + 1: 01000111
num = num1 & num2; print(num) # 按位与运算：00000100
num = num1 | num2; print(num) # 按位或运算：01001111
# 01000111 + 00000001 = 01001000 =>(符号反转) 11001000
num = ~num2; print(num)       # 按位取反运算 ：~x <===> -x-1  ~89 = -90
num = num1 ^ num2; print(num) # 按位异或：01001011 => 75
num = num2 << 1; print(num)   # 左移：01000111 ===>(左移) 10001110: 142
num = num2 >> 2; print(num)   # 右移：01000111 ===>(右移) 00010001: 17

# 逻辑运算符：and, or, not
flag1 = True
flag2 = False
print(flag1 and flag2) # 有假取假：False
print(flag1 or flag2)  # 有真取真：True
print(not flag1)       # 取反：False

# 成员运算符：in, not in
list3 = [1,2,3,5,"djlaskjd"]
print("hello" in list3) # False，"hello"不在列表list3中

# 身份运算符：is, is not(身份运算符is，not is比较的是数据所在地址，并非数据本身值)
a = "coucou"; b = "coucou"
print(a is b)           # True
list4 = [1,2,3]; list5 = [1,2,3]
print(list4 is list5)   # False
list4 = list5           # 将list5的地址赋值给list4，其指向同一片内存
list4[2] = 9            
print(list5[2])         # 修改list4的2位置会影响到list5